﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LcAudit.BPM.Core.Dal;
using LcAudit.Common.Provider;
using LcAudit.Common;
using LcAudit.BPM.Core.Model;

namespace LcAudit.BPM.Core.Bll
{
    public class TenderBll
    {
        public static TenderBll Instance
        {
            get { return SingletonProvider<TenderBll>.Instance; }
        }
        public string Add(tenderinfo u)
        {
            int uid = 0;
            string msg = "添加失败！";
            uid = TenderDal.Instance.Insert(u,new string[]{"keyid","tdate"});
            if (uid > 0)
            {
                msg = "添加成功！";
            }

            return new JsonMessage { Data = uid.ToString(), Message = msg, Success = uid > 0 }.ToString();
        }

        public string Edit(tenderinfo u)
        {
            int k;
            string msg = "编辑失败。";
            u.tdate = DateTime.Now;
            k = TenderDal.Instance.Update(u, new[] {"keyid", "tdate" });
            if (k > 0)
            {
                msg = "编辑成功。";
            }

            return new JsonMessage { Data = k.ToString(), Message = msg, Success = k > 0 }.ToString();
        }

        public string Delete(int Id)
        {
            string msg = "删除失败！";
            int k = 0;

            k = TenderDal.Instance.Delete(Id);
            if (k > 0)
            {
                msg = "删除成功。";
            }

            return new JsonMessage { Data = k.ToString(), Message = msg, Success = k > 0 }.ToString();
        }
        public string GetList()
        {
            var devList = TenderDal.Instance.GetAll();
            var list = devList as List<tenderinfo> ?? devList.ToList();
            return list.Any() ? JSONhelper.ToJson(list) : "[]";
        }
        public string GetListUse()
        {
            var devList = TenderDal.Instance.GetListBy();
            var list = devList as List<tenderinfo> ?? devList.ToList();
            return list.Any() ? JSONhelper.ToJson(list) : "[]";
        }

    }
}
